{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "library(lisi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"SCALEX\"\n",
      "[1] \"LIGER\"\n",
      "[1] \"online_iNMF\"\n",
      "[1] \"Harmony\"\n",
      "[1] \"Seurat_v3\"\n",
      "[1] \"Conos\"\n",
      "[1] \"FastMNN\"\n",
      "[1] \"Raw\"\n",
      "[1] \"Scanorama\"\n",
      "[1] \"BBKNN\"\n",
      "[1] \"scVI\"\n",
      "[1] \"SCALEX\"\n",
      "[1] \"LIGER\"\n",
      "[1] \"online_iNMF\"\n",
      "[1] \"Harmony\"\n",
      "[1] \"Seurat_v3\"\n",
      "[1] \"Conos\"\n",
      "[1] \"FastMNN\"\n",
      "[1] \"Raw\"\n",
      "[1] \"Scanorama\"\n",
      "[1] \"BBKNN\"\n",
      "[1] \"scVI\"\n",
      "[1] \"SCALEX\"\n",
      "[1] \"LIGER\"\n",
      "[1] \"online_iNMF\"\n",
      "[1] \"Harmony\"\n",
      "[1] \"Seurat_v3\"\n",
      "[1] \"Conos\"\n",
      "[1] \"FastMNN\"\n",
      "[1] \"Raw\"\n",
      "[1] \"Scanorama\"\n",
      "[1] \"BBKNN\"\n",
      "[1] \"scVI\"\n"
     ]
    }
   ],
   "source": [
    "for(dataset in c('pancreas','PBMC','liver','heart','NSCLC'))\n",
    "{\n",
    "    items <- c('SCALEX','LIGER','online_iNMF','Harmony','Seurat_v3','Conos','FastMNN', 'Raw', 'Scanorama', 'BBKNN', 'scVI')\n",
    "    path <- '~/SCALEX/notebook/benchmark/LISI/data/'\n",
    "    batch_id <- read.table(paste(path,dataset,'/','batch.txt',sep=''),sep='\\t',header = F)\n",
    "    celltype <- read.table(paste(path,dataset,'/','celltype.txt',sep=''),sep='\\t',header = F)\n",
    "    metadata=cbind(batch_id,celltype)\n",
    "    colnames(metadata)=c('batch','celltype')\n",
    "\n",
    "    lisi_res <- list()\n",
    "    for(item in items){\n",
    "        if(file.exists(paste(path,dataset,'/',item,'.txt',sep=''))){\n",
    "            print(item)\n",
    "            umap <- read.table(paste(path,dataset,'/',item,'.txt',sep=''))\n",
    "            result <- lisi::compute_lisi(umap, metadata, c('batch', 'celltype'))\n",
    "            lisi_res <- append(lisi_res, data.frame(result))\n",
    "        }\n",
    "    }\n",
    "    lisi_res <- Reduce(cbind,lisi_res)\n",
    "    lisi_res = round(lisi_res,5)\n",
    "\n",
    "    colnames(lisi_res) <- c('SCALEX_batch','SCALEX_celltype','LIGER_batch','LIGER_celltype','online_iNMF_batch','online_iNMF_celltype','Harmony_batch','Harmony_celltype',\n",
    "                            'Seurat_v3_batch','Seurat_v3_celltype','Conos_batch','Conos_celltype',\n",
    "                            'FastMNN_batch','FastMNN_celltype','Raw_batch','Raw_celltype','Scanorama_batch','Scanorama_celltype',\n",
    "                            'BBKNN_batch','BBKNN_celltype','scVI_batch','scVI_celltype')\n",
    "\n",
    "    write.table(lisi_res,paste(path,dataset,'/','lisi_res.txt',sep=''),sep='\\t',quote=F)\n",
    "    }\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "4.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
